package leetcode.中等;

import org.junit.Test;

/**
 * 动态规划
 * 以某个节点的结束为条件来遍历
 */
public class leetcode53_最大子数组和 {

    @Test
    public void test(){
        int[] nums = new int[]{1,3,-5,5,-7,9,9};
        System.out.println(maxSubArray(nums));
    }

    /**
     * 1.判断是否重复
     * 2.判断大小
     * @param nums
     * @return
     */
    public int maxSubArray(int[] nums) {
        int result = 0;
        int pre = 0;

        for (int i = 0; i < nums.length; i ++){
            pre = Math.max(nums[i],pre+nums[i]);
            result = Math.max(pre,result);
        }
        return result;
    }
}
